package com.woniu.service.util;

import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;


public class FileUpload {
    public static String upload(MultipartFile file) {
        //图片的原始名称
        String originalFilename = file.getOriginalFilename();
        String uuid = UUID.randomUUID().toString().replace("-", "").toUpperCase();

        String fileName = uuid + "_" + originalFilename;

        // 使用multipart对象的方法保存文件
        try {
            // 就是将上传的文件流保存指定路径下
            OkHttpUtils.uploadFile(file, "http://192.168.201.41:8006/util/upload", fileName);

        } catch (IOException e) {
            e.printStackTrace();
        }
        return fileName;
    }

}
